<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
	<link rel="stylesheet" href="front/css/bootstrap-datetimepicker.css"  type="text/css" >
	<!--下拉框 -->
	<link rel="stylesheet" href="front/css/chosen.css" type="text/css" />
	<link rel="stylesheet" href="front/css/normal.css">
	<link rel="stylesheet" href="front/css/addBox.css">
	<link rel="stylesheet" href="static/css/finance.css" />
	<link rel='stylesheet' href='front/css/dialog.css'>
	<script src="front/js/jquery-2.0.3.min.js"></script>

</head>
<body style='width:1100px'>
	<p class="addSlide-title">预借款申请单<span>×</span></p>
	<form action="borrowmoney/${msg }.do" name="Form" id="Form"	method="post" style="margin: 0 auto;" enctype="multipart/form-data">
		<div id="zhongxin">
			<input type="hidden" name="bm_id" id="bm_id" value="${pd.bm_id}" />
			<input type="hidden" name="bm_status" id="bm_status"/>
			<p class="loanTitle">预借款申请单</p>
			<table class="tableListBorder">
				<colgroup>
					<col width="120px">
					<col width="150px">
					<col width="120px">
					<col width="250px">
					<col width="120px">
					<col>
				</colgroup>
				<tbody>
					<tr>
						<td style='text-align: center'>借款人姓名</td>
						<td><input class="fieldEditable" type="text" name="USERNAME" value="${pd.USERNAME}" readonly="readonly"></td>
						<td style='text-align: center'>所属部门</td>
						<td><input type="text" class="fieldEditable" name="department_name" value="${pd.department_name}" readonly="readonly"></td>
						<td style='text-align: center'>申请单号</td>
						<td><input id="application_no" class="fieldEditable" name="application_no" value="${pd.application_no}"	class="fieldEditable" readonly="readonly"></td>
					</tr>
				</tbody>
			</table>
			<table class="tableListBorder2">
				<colgroup>
					<col width="120">
					<col>
					<col width="120">
					<col width="350">
				</colgroup>
				<tbody>
					<tr>
						<td><span class="redStar">*</span>借款事由</td>
						<td colspan="3"><textarea name="bm_reason" id="bm_reason" class="loanTextarea">${pd.bm_reason}</textarea></td>
					</tr>
					<tr>
						<td><span class="redStar">*</span>借款金额</td>
						<td><input onblur="inputOnBlur()"  id="bm_amount" name="bm_amount" value="${pd.bm_amount}" type="number" class="fieldEditable"></td>
						<td>金额大写</td>
						<td><input id="capital" readonly="readonly" name="capital" value="${pd.capital}" type="text" class="fieldEditable"></td>
					</tr>
					<tr>
						<td>借款方式</td>
						<td><select style="width: 350px;" name="bm_way" onchange="select()" id="bm_way" class='select'>
								<option value="0" <c:if test="${pd.bm_way==0}" >selected="selected" </c:if>>现金</option>
								<option value="1" <c:if test="${pd.bm_way==1}" >selected="selected" </c:if>>转账</option>
								<option value="2" <c:if test="${pd.bm_way==2}" >selected="selected" </c:if>>其它</option>
						</select></td>
						<!-- <td>未还款金额(元)</td>
						<td><input type="text" class="fieldEditable"></td> -->
						<td>申请日期</td>
						<td>
						<c:if test="${pd.bm_time==null}">
							<input id="bm_time" name="bm_time" value="${pd.bm_time}" class='fieldEditable form_datetime date'>
						</c:if>
						<c:if test="${pd.bm_time!=null}">
							<fmt:formatDate value="${pd.bm_time}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</c:if>
						</td>
					</tr>
					<tr>
						<td><span class="redStar">*</span>预计还款日期</td>
						<td><input class="fieldEditable form_datetime date" type="text" name="repayment_time" id="repayment_time" value="${pd.repayment_time}"></td>
						<td><span class="redStar">*</span>最迟到账时间</td>
						<td><input id="accounting_date" name="accounting_date" value="${pd.accounting_date}" class="fieldEditable form_datetime date">
						</td> 
					</tr>
					<tr class="accountclass">
						<td><span class="redStar">*</span>账户名称</td>
						<td><input type="text" class="fieldEditable" name="bm_account" id="bm_account" value="${pd.bm_account}">
						</td>
					    <td><span class="redStar">*</span>银行账号</td>
						<td><input class="fieldEditable" name="bm_card_numbers" id="bm_card_numbers" value="${pd.bm_card_numbers}">
						</td> 

					</tr>
					<tr class="accountclass">
						<td><span class="redStar">*</span>开户银行</td>
						<td colspan="3"><input class="fieldEditable" name="opening_bank" id="opening_bank" value="${pd.opening_bank}">
						</td>
					</tr>
				</tbody>
			</table>
			<c:if test="${pd.bm_attach_path  !=null && pd.bm_attach_name !=''}">
				<p>
					点击下载：<a class="btn btn-mini btn-primary" href="192.168.198.251:8080/${pd.bm_attach_path}">${pd.bm_attach_name}</a>
				</p>
			</c:if>
			<c:if test="${pd.bm_attach_path  ==null || pd.bm_attach_path ==''}">
				<span>上传附件:</span>
			 	<a class="file operatea upload">点击上传文件<input type="file" name="bm_attach_path">
		            <span></span>
		        </a>
			</c:if>
			<p class="btn-box">
				<input class="confirmSave" type='button' onclick="save();" value='保存'>
				<input class="confirmSave" type='button' onclick="apply();" value='提交主管审批'>
				<input type="button" onclick="cancel();" value="取消保存" class="cancelSave">
			</p>
		</div>
		
	</form>




	<!-- 下拉框 -->
	<script src="front/js/chosen.jquery.js"></script>
	<!-- 日历插件 -->
	<script src="front/js/bootstrap-datetimepicker.js"></script>
	<script src="front/js/jquery.tips.js"></script>
	<!-- 弹框提示的 -->
	<script src='front/js/dialog.js'></script>
	<script src="front/js/index.js"></script>
	<!-- 日期框 -->
	<script>
		$(function() {
			//日期插件
			$(".form_datetime").datetimepicker( {
		        autoclose:true,
		        format: "yyyy-mm-dd",
		        language: 'cn',
		        clearBtn:true,
		        todayHighlight: true,
				minView:2
		     });
			 //下拉框
		     $(".select").chosen();
	
			 //上传文件
		      $(document).on('change','input[type="file"]',function(){
		          var filePath = $(this).val();
		          $(this).next().html(insertTitle(filePath));
		      });
	
		   var myDate  = new Date();
		   var no="";
		   no=myDate.getFullYear()+myDate.getMonth()+myDate.getDate()+myDate.getTime(); 
		   var application =$("#application_no").val();
		   if (application=='' || application==null) {
		 	  $("#application_no").val(no);
		   }
		   
		   
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    $("#bm_time").val(currentdate);
		   
		   
		   
		    $(".fieldSource").click(function(){
		        $(this).next('.depart').toggle();
		    });
		
		    $(document).on('click','.depart li',function(){
		        $(".bumen").html($(this).html());
		        $(this).parent().hide();
		    });
		    
		    
		    var way=$("#bm_way").val();
			if(way=='0'){
				$(".accountclass").hide();
			}else{
				$(".accountclass").show();
			}
			
		})
		
		function cancel(){
			$('#zhongxin', parent.document).hide();
	    } 
		
		function select(){
			var way=$("#bm_way").val();
			if(way=='0'){
				$(".accountclass").hide();
			}else{
				$(".accountclass").show();
			}
		}

		
		function inputOnBlur(){
		    var all=$("#bm_amount").val();
		    if (all<0) {
		    	$.alert("价格不能为负数！"); 
		    	$("#bm_amount").val("0");
		    	return false;
			}else{
		    var sum=digitUppercase(all);
		    $("#capital").val(sum);
			}
		}
			
		//保存
		function save(){
		   if($("#bm_reason").val()==""){
				ok=false;
				$("#bm_reason").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#bm_reason").focus();
				return ;
			}
			if($("#bm_amount").val()==""){
				ok=false;
				$("#bm_amount").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#bm_amount").focus();
				return ;
			}
			if($("#repayment_time").val()==""){
				ok=false;
				$("#repayment_time").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#repayment_time").focus();
				return ;
			}
			if($("#accounting_date").val()==""){
				ok=false;
				$("#accounting_date").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#accounting_date").focus();
				return ;
			}
			if ($("#bm_way").val()=="1") {
				if($("#bm_account").val()==""){
					ok=false;
					$("#bm_account").tips({
						side:3,
			            msg:'请输入',
			            bg:'#AE81FF',
			            time:2
			        });
					$("#bm_account").focus();
					return ;
				}
				if($("#bm_card_numbers").val()==""){
					ok=false;
					$("#bm_card_numbers").tips({
						side:3,
			            msg:'请输入',
			            bg:'#AE81FF',
			            time:2
			        });
					$("#bm_card_numbers").focus();
					return ;
				}
				if($("#opening_bank").val()==""){
					ok=false;
					$("#opening_bank").tips({
						side:3,
			            msg:'请输入',
			            bg:'#AE81FF',
			            time:2
			        });
					$("#opening_bank").focus();
					return ;
				}
			}
			$("#bm_status").val('0');
			$("#Form").submit();
		}
		
		
		//保存
		function apply(){
			if($("#bm_reason").val()==""){
				ok=false;
				$("#bm_reason").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#bm_reason").focus();
				return ;
			}
			if($("#bm_amount").val()==""){
				ok=false;
				$("#bm_amount").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#bm_amount").focus();
				return ;
			}
			if($("#repayment_time").val()==""){
				ok=false;
				$("#repayment_time").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#repayment_time").focus();
				return ;
			}
			if($("#accounting_date").val()==""){
				ok=false;
				$("#accounting_date").tips({
					side:3,
		            msg:'请输入',
		            bg:'#AE81FF',
		            time:2
		        });
				$("#accounting_date").focus();
				return ;
			}
			if ($("#bm_way").val()=="1") {
				if($("#bm_account").val()==""){
					ok=false;
					$("#bm_account").tips({
						side:3,
			            msg:'请输入',
			            bg:'#AE81FF',
			            time:2
			        });
					$("#bm_account").focus();
					return ;
				}
				if($("#bm_card_numbers").val()==""){
					ok=false;
					$("#bm_card_numbers").tips({
						side:3,
			            msg:'请输入',
			            bg:'#AE81FF',
			            time:2
			        });
					$("#bm_card_numbers").focus();
					return ;
				}
				if($("#opening_bank").val()==""){
					ok=false;
					$("#opening_bank").tips({
						side:3,
			            msg:'请输入',
			            bg:'#AE81FF',
			            time:2
			        });
					$("#opening_bank").focus();
					return ;
				}
			}
			$("#bm_status").val('1');
			$("#Form").submit();
		}
		
		 var digitUppercase = function(n) {  
	         var fraction = ['角', '分'];  
	         var digit = [  
	             '零', '壹', '贰', '叁', '肆',  
	             '伍', '陆', '柒', '捌', '玖'  
	         ];  
	         var unit = [  
	             ['元', '万', '亿'],  
	             ['', '拾', '佰', '仟']  
	         ];  
	         var head = n < 0 ? '欠' : '';  
	         n = Math.abs(n);  
	         var s = '';  
	         var sum = '';  
	         for (var i = 0; i < fraction.length; i++) {  
	             s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');  
	         }  
	         s = s || '整';  
	         n = Math.floor(n);  
	         for (var i = 0; i < unit[0].length && n > 0; i++) {  
	             var p = '';  
	             for (var j = 0; j < unit[1].length && n > 0; j++) {  
	                 p = digit[n % 10] + unit[1][j] + p;  
	                 n = Math.floor(n / 10);  
	             }  
	             s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;  
	         }  
	         return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整'); 
	     };
		    	
         </script>
</body>
</html>